#include "ConfigSaveLoader.h"

#include <QJsonDocument>
#include <QJsonParseError>
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonValue>
#include <QFile>

#include "DataLimit.h"

//UI层
#include "MemsAutoTestSoftware.h"
#include "ParameterConsole.h"
#include "SetPositionModeDialog.h"
#include "SetRateModeDialog.h"
#include "SetTurnTableAndThermostatDialog.h"
//功能层
#include "MEMSDataHandler.h"
#include "MEMSDataSaver.h"
#include "ScriptRunner.h"
#include "TurnTableCodec.h"
#include "LogSaver.h"
//IO层
#include "FileReader.h"
#include "FileWriter.h"
#include "SerialPortManager.h"

ConfigSaveLoader::ConfigSaveLoader(QObject* parent) :QObject(parent)
{
}

ConfigSaveLoader::~ConfigSaveLoader()
{
}
void ConfigSaveLoader::slot_saveConfig()
{
	QJsonObject config;
	//UI层
	saveConfig_MemsAutoTestSoftware(&config);
	//功能层
	saveConfig_MEMSData(&config);
	saveConfig_Script(&config);
	saveConfig_TurnTableCodec(&config);
	saveConfig_LogSaver(&config);
	//IO层
	saveConfig_SerialPortManager(&config);
	QJsonDocument document;
	document.setObject(config);
	QByteArray configArray = document.toJson();
	fileWriter->saveAsFile<ConfigSaveLoader>(configFilePath, configArray,FileWriter::WriteToFile,this, &ConfigSaveLoader::signal_writeConfigFileSuccessful,&ConfigSaveLoader::signal_writeConfigFileFailed);
}

void ConfigSaveLoader::slot_loadConfig()
{
	fileReader->readFromFile<ConfigSaveLoader>(configFilePath,this,&ConfigSaveLoader::slot_configFileData,&ConfigSaveLoader::signal_openConfigFileFailed);
}

void ConfigSaveLoader::slot_configFileData(QString filePath, QByteArray data)
{
	QJsonParseError qJsonParseError;
	QJsonDocument document = QJsonDocument::fromJson(data, &qJsonParseError);
	if (qJsonParseError.error == QJsonParseError::NoError)
	{
		if (document.isObject())
		{
			QJsonObject config = document.object();
			//UI层
			loadConfig_MemsAutoTestSoftware(&config);
			//功能层
			loadConfig_MEMSData(&config);
			loadConfig_Script(&config);
			loadConfig_TurnTableCodec(&config);
			loadConfig_LogSaver(&config);
			//IO层
			loadConfig_SerialPortManager(&config);
			emit signal_loadConfigSuccessful(filePath);
		}
	}
}

//UI层
void ConfigSaveLoader::saveConfig_MemsAutoTestSoftware(QJsonObject* config)
{
	config->insert(memsAutoTestSoftware_dataAccuracy, parameterConsole->getMEMSAutoTestSoftware_accuracy());
}
void ConfigSaveLoader::loadConfig_MemsAutoTestSoftware(QJsonObject* config)
{
	bool isCan;
	if (config->contains(memsAutoTestSoftware_dataAccuracy))
	{
		QJsonValue temp=(*config)[memsAutoTestSoftware_dataAccuracy];
		if (temp.isDouble())
		{
			int value = temp.toInt();
			value = DataLimit::standardizeMEMSDataAccuracy_display(value);
			memsAutoTestSoftware->setAccuracy(value);
			parameterConsole->setMEMSAutoTestSoftware_accuracy(value);
			setTurnTableAndThermostatDialog->setAccuracy(value);
			setPositionModeDialog->setAccuracy(value);
			setRateModeDialog->setAccuracy(value);
		}
	}
}
//功能层
void ConfigSaveLoader::saveConfig_MEMSData(QJsonObject* config)
{
	config->insert(mEMSData_dataSavingAccuracy, parameterConsole->getMEMSData_accuracy());
	config->insert(mEMSData_interval_handleData, parameterConsole->getMEMSData_interval_collection());
	QJsonArray mEMSFilePathArray;
	for (QString filePath: mEMSDataSaver->getFilePaths())
	{
		mEMSFilePathArray.append(filePath);
	}
	config->insert(mEMSData_filePaths, mEMSFilePathArray);
	config->insert(mEMSData_dataPackagetype,mEMSDataCodec->getDataPackagetype());
	config->insert(mEMSData_dataCollectionProtocol,mEMSDataHandler->getDataCollectionProtocol());
}
void ConfigSaveLoader::loadConfig_MEMSData(QJsonObject* config)
{
	bool isCan;
	if (config->contains(mEMSData_dataSavingAccuracy))
	{
		QJsonValue temp = (*config)[mEMSData_dataSavingAccuracy];
		if (temp.isDouble())
		{
			int value = temp.toInt();
			value = DataLimit::standardizeMEMSDataAccuracy_save(value);
			mEMSDataSaver->setAccuracy(value);
			parameterConsole->setMEMSData_accuracy(value);
		}
	}
	if (config->contains(mEMSData_interval_handleData))
	{
		QJsonValue temp = (*config)[mEMSData_interval_handleData];
		if (temp.isDouble())
		{
			int value = temp.toInt();
			value = DataLimit::standardizeMEMSDataCollectionInterval(value);
			mEMSDataHandler->setInterval_collection(value);
			parameterConsole->setMEMSData_interval_collection(value);
		}
	}
	if (config->contains(mEMSData_filePaths))
	{
		QJsonValue temp = (*config)[mEMSData_filePaths];
		if (temp.isArray())
		{
			QJsonArray values = temp.toArray();
			for (int i=0;i<values.size();++i)
			{
				QJsonValue value = values[i];
				if (value.isString())
				{
					mEMSDataSaver->setFilePath(i,value.toString());
				}
			}
		}
	}
	if (config->contains(mEMSData_dataPackagetype))
	{
		QJsonValue temp = (*config)[mEMSData_dataPackagetype];
		if (temp.isDouble())
		{
			switch (temp.toInt())
			{
			case MEMSDataCodec::Single:
				mEMSDataCodec->setDataPackagetype(MEMSDataCodec::Single);
				break;
			case MEMSDataCodec::Multi:
				mEMSDataCodec->setDataPackagetype(MEMSDataCodec::Multi);
				break;
			default:
				break;
			}
		}
	}
	if (config->contains(mEMSData_dataCollectionProtocol))
	{
		QJsonValue temp = (*config)[mEMSData_dataCollectionProtocol];
		if (temp.isDouble())
		{
			switch (temp.toInt())
			{
			case MEMSDataHandler::Protocol_SingleTemperature:
				mEMSDataHandler->setDataCollectionProtocol(MEMSDataHandler::Protocol_SingleTemperature);
				break;
			case MEMSDataHandler::Protocol_DoubleTemperature:
				mEMSDataHandler->setDataCollectionProtocol(MEMSDataHandler::Protocol_DoubleTemperature);
				break;
			default:
				break;
			}
		}
	}
}
void ConfigSaveLoader::saveConfig_Script(QJsonObject* config)
{
	config->insert(scriptRunner_interval_turnTableOperationTimeOut, parameterConsole->getScriptManage_interval_turnTableOperationTimeOut());
}
void ConfigSaveLoader::loadConfig_Script(QJsonObject* config)
{
	bool isCan;
	if (config->contains(scriptRunner_interval_turnTableOperationTimeOut))
	{
		QJsonValue temp = (*config)[scriptRunner_interval_turnTableOperationTimeOut];
		if (temp.isDouble())
		{
			int value = temp.toInt();
			value = DataLimit::standardizeScriptManageTurnTableOperationTimeOutInterval(value);
			scriptRunner->setInterval_instruction(value);
			parameterConsole->setScriptManage_interval_turnTableOperationTimeOut(value);
		}
	}
}
void ConfigSaveLoader::saveConfig_TurnTableCodec(QJsonObject* config)
{
	config->insert(turnTableCodec_turnTablePositionUpperLimit, parameterConsole->getTurnTable_positionUpperLimit());
	config->insert(turnTableCodec_turnTablePositionLowerLimit, parameterConsole->getTurnTable_positionLowerLimit());
	config->insert(turnTableCodec_turnTableRateUpperLimit, parameterConsole->getTurnTable_rateUpperLimit());
	config->insert(turnTableCodec_turnTableRateLowerLimit, parameterConsole->getTurnTable_rateLowerLimit());
	config->insert(turnTableCodec_turnTableAccelerationUpperLimit, parameterConsole->getTurnTable_accelerationUpperLimit());
	config->insert(turnTableCodec_turnTableAccelerationLowerLimit, parameterConsole->getTurnTable_accelerationLowerLimit());
}
void ConfigSaveLoader::loadConfig_TurnTableCodec(QJsonObject* config)
{
	if (config->contains(turnTableCodec_turnTablePositionUpperLimit))
	{
		QJsonValue temp = (*config)[turnTableCodec_turnTablePositionUpperLimit];
		if (temp.isDouble())
		{
			int value = temp.toInt();
			value = DataLimit::standardizeTurnTablePositionLimit(value);
			turnTableCodec->setTurnTablePositionUpperLimit(value);
			setPositionModeDialog->setTurnTablePositionUpperLimit(value);
			setTurnTableAndThermostatDialog->setTurnTable_positionUpperLimit(value);
			parameterConsole->setTurnTable_positionUpperLimit(value);
		}
	}
	if (config->contains(turnTableCodec_turnTablePositionLowerLimit))
	{
		QJsonValue temp = (*config)[turnTableCodec_turnTablePositionLowerLimit];
		if (temp.isDouble())
		{
			int value = temp.toInt();
			value= DataLimit::standardizeTurnTablePositionLimit(value);
			int positionUpperLimit = parameterConsole->getTurnTable_positionUpperLimit();
			if (value> positionUpperLimit)
			{
				turnTableCodec->setTurnTablePositionLowerLimit(positionUpperLimit);
				setPositionModeDialog->setTurnTablePositionLowerLimit(positionUpperLimit);
				setTurnTableAndThermostatDialog->setTurnTable_positionLowerLimit(positionUpperLimit);
				parameterConsole->setTurnTable_positionLowerLimit(positionUpperLimit);
			}
			else
			{
				turnTableCodec->setTurnTablePositionLowerLimit(value);
				setPositionModeDialog->setTurnTablePositionLowerLimit(value);
				setTurnTableAndThermostatDialog->setTurnTable_positionLowerLimit(value);
				parameterConsole->setTurnTable_positionLowerLimit(value);
			}
		}
	}
	if (config->contains(turnTableCodec_turnTableRateUpperLimit))
	{
		QJsonValue temp = (*config)[turnTableCodec_turnTableRateUpperLimit];
		if (temp.isDouble())
		{
			int value = temp.toInt();
			value = DataLimit::standardizeTurnTableRateLimit(value);
			turnTableCodec->setTurnTableRateUpperLimit(value);
			setPositionModeDialog->setTurnTableRateUpperLimit(value);
			setRateModeDialog->setTurnTableRateUpperLimit(value);
			setTurnTableAndThermostatDialog->setTurnTable_rateUpperLimit(value);
			parameterConsole->setTurnTable_rateUpperLimit(value);
		}
	}
	if (config->contains(turnTableCodec_turnTableRateLowerLimit))
	{
		QJsonValue temp = (*config)[turnTableCodec_turnTableRateLowerLimit];
		if (temp.isDouble())
		{
			int value = temp.toInt();
			value= DataLimit::standardizeTurnTableRateLimit(value);
			int rateUpperLimit = parameterConsole->getTurnTable_rateUpperLimit();
			if (value > rateUpperLimit)
			{
				turnTableCodec->setTurnTableRateLowerLimit(rateUpperLimit);
				setPositionModeDialog->setTurnTableRateLowerLimit(rateUpperLimit);
				setRateModeDialog->setTurnTableRateLowerLimit(rateUpperLimit);
				setTurnTableAndThermostatDialog->setTurnTable_rateLowerLimit(rateUpperLimit);
				parameterConsole->setTurnTable_rateLowerLimit(rateUpperLimit);
			}
			else
			{
				turnTableCodec->setTurnTableRateLowerLimit(value);
				setPositionModeDialog->setTurnTableRateLowerLimit(value);
				setRateModeDialog->setTurnTableRateLowerLimit(value);
				setTurnTableAndThermostatDialog->setTurnTable_rateLowerLimit(value);
				parameterConsole->setTurnTable_rateLowerLimit(value);
			}
		}
	}
	if (config->contains(turnTableCodec_turnTableAccelerationUpperLimit))
	{
		QJsonValue temp = (*config)[turnTableCodec_turnTableAccelerationUpperLimit];
		if (temp.isDouble())
		{
			int value = temp.toInt();
			value = DataLimit::standardizeTurnTableAccelerationLimit(value);
			turnTableCodec->setTurnTableAccelerationUpperLimit(value);
			setPositionModeDialog->setTurnTableAccelerationUpperLimit(value);
			setRateModeDialog->setTurnTableAccelerationUpperLimit(value);
			setTurnTableAndThermostatDialog->setTurnTable_accelerationUpperLimit(value);
			parameterConsole->setTurnTable_accelerationUpperLimit(value);
		}
	}
	if (config->contains(turnTableCodec_turnTableAccelerationLowerLimit))
	{
		QJsonValue temp = (*config)[turnTableCodec_turnTableAccelerationLowerLimit];
		if (temp.isDouble())
		{
			int value = temp.toInt();
			value = DataLimit::standardizeTurnTableAccelerationLimit(value);
			int accelerationUpperLimit = parameterConsole->getTurnTable_accelerationUpperLimit();
			if (value> accelerationUpperLimit)
			{
				turnTableCodec->setTurnTableAccelerationLowerLimit(accelerationUpperLimit);
				setPositionModeDialog->setTurnTableAccelerationLowerLimit(accelerationUpperLimit);
				setRateModeDialog->setTurnTableAccelerationLowerLimit(accelerationUpperLimit);
				setTurnTableAndThermostatDialog->setTurnTable_accelerationLowerLimit(accelerationUpperLimit);
				parameterConsole->setTurnTable_accelerationLowerLimit(accelerationUpperLimit);
			}
			else
			{
				turnTableCodec->setTurnTableAccelerationLowerLimit(value);
				setPositionModeDialog->setTurnTableAccelerationLowerLimit(value);
				setRateModeDialog->setTurnTableAccelerationLowerLimit(value);
				setTurnTableAndThermostatDialog->setTurnTable_accelerationLowerLimit(value);
				parameterConsole->setTurnTable_accelerationLowerLimit(value);
			}
		}
	}
}
void ConfigSaveLoader::saveConfig_LogSaver(QJsonObject* config)
{
	config->insert(logSaver_logLevel,logSaver->getLogLevel());
}
void ConfigSaveLoader::loadConfig_LogSaver(QJsonObject* config)
{
	if (config->contains(logSaver_logLevel))
	{
		QJsonValue temp = (*config)[logSaver_logLevel];
		if (temp.isDouble())
		{
			int value = temp.toInt();
			if ((value &LogSaver::Debug))
			{
				logSaver->enableLogLevel(LogSaver::Debug);
			}
			if ((value & LogSaver::Information))
			{
				logSaver->enableLogLevel(LogSaver::Information);
			}
			if ((value & LogSaver::Warning))
			{
				logSaver->enableLogLevel(LogSaver::Warning);
			}
			if ((value & LogSaver::Critical))
			{
				logSaver->enableLogLevel(LogSaver::Critical);
			}
		}
	}
}
//IO层
void ConfigSaveLoader::saveConfig_SerialPortManager(QJsonObject* config)
{
	config->insert(serialPortManager_turnTable_portName,serialPortManager_turnTable->portName());
	config->insert(serialPortManager_turnTable_baudRate, serialPortManager_turnTable->baudRate());
	config->insert(serialPortManager_turnTable_parity,serialPortManager_turnTable->parity());
	config->insert(serialPortManager_turnTable_dataBits, serialPortManager_turnTable->dataBits());
	config->insert(serialPortManager_turnTable_stopBits, serialPortManager_turnTable->stopBits());
	config->insert(serialPortManager_turnTable_flowControl, serialPortManager_turnTable->flowControl());

	config->insert(serialPortManager_mEMSData_portName, serialPortManager_mEMSData->portName());
	config->insert(serialPortManager_mEMSData_baudRate, serialPortManager_mEMSData->baudRate());
	config->insert(serialPortManager_mEMSData_parity, serialPortManager_mEMSData->parity());
	config->insert(serialPortManager_mEMSData_dataBits, serialPortManager_mEMSData->dataBits());
	config->insert(serialPortManager_mEMSData_stopBits, serialPortManager_mEMSData->stopBits());
	config->insert(serialPortManager_mEMSData_flowControl, serialPortManager_mEMSData->flowControl());
}
void ConfigSaveLoader::loadConfig_SerialPortManager(QJsonObject* config)
{
	if (config->contains(serialPortManager_turnTable_portName))
	{
		QJsonValue temp = (*config)[serialPortManager_turnTable_portName];
		if (temp.isString())
		{
			serialPortManager_turnTable->setPortName(temp.toString());
		}
	}
	if (config->contains(serialPortManager_mEMSData_portName))
	{
		QJsonValue temp = (*config)[serialPortManager_mEMSData_portName];
		if (temp.isString())
		{
			serialPortManager_mEMSData->setPortName(temp.toString());
		}
	}
	if (config->contains(serialPortManager_turnTable_baudRate))
	{
		QJsonValue temp = (*config)[serialPortManager_turnTable_baudRate];
		if (temp.isDouble())
		{
			serialPortManager_turnTable->setBaudRate(temp.toInt());
		}
	}
	if (config->contains(serialPortManager_mEMSData_baudRate))
	{
		QJsonValue temp = (*config)[serialPortManager_mEMSData_baudRate];
		if (temp.isDouble())
		{
			serialPortManager_mEMSData->setBaudRate(temp.toInt());
		}
	}
	if (config->contains(serialPortManager_turnTable_parity))
	{
		QJsonValue temp = (*config)[serialPortManager_turnTable_parity];
		if (temp.isDouble())
		{
			switch (temp.toInt())
			{
			case QSerialPort::NoParity:
				serialPortManager_turnTable->setParity(QSerialPort::NoParity);
				break;
			case QSerialPort::EvenParity:
				serialPortManager_turnTable->setParity(QSerialPort::EvenParity);
				break;
			case QSerialPort::OddParity:
				serialPortManager_turnTable->setParity(QSerialPort::OddParity);
				break;
			default:
				break;
			}
		}
	}
	if (config->contains(serialPortManager_mEMSData_parity))
	{
		QJsonValue temp = (*config)[serialPortManager_mEMSData_parity];
		if (temp.isDouble())
		{
			switch (temp.toInt())
			{
			case QSerialPort::NoParity:
				serialPortManager_mEMSData->setParity(QSerialPort::NoParity);
				break;
			case QSerialPort::EvenParity:
				serialPortManager_mEMSData->setParity(QSerialPort::EvenParity);
				break;
			case QSerialPort::OddParity:
				serialPortManager_mEMSData->setParity(QSerialPort::OddParity);
				break;
			default:
				break;
			}
		}
	}
	if (config->contains(serialPortManager_turnTable_dataBits))
	{
		QJsonValue temp = (*config)[serialPortManager_turnTable_dataBits];
		if (temp.isDouble())
		{
			switch (temp.toInt())
			{
			case QSerialPort::Data5:
				serialPortManager_turnTable->setDataBits(QSerialPort::Data5);
				break;
			case QSerialPort::Data6:
				serialPortManager_turnTable->setDataBits(QSerialPort::Data6);
				break;
			case QSerialPort::Data7:
				serialPortManager_turnTable->setDataBits(QSerialPort::Data7);
				break;
			case QSerialPort::Data8:
				serialPortManager_turnTable->setDataBits(QSerialPort::Data8);
				break;
			default:
				break;
			}
		}
	}

	if (config->contains(serialPortManager_mEMSData_dataBits))
	{
		QJsonValue temp = (*config)[serialPortManager_turnTable_dataBits];
		if (temp.isDouble())
		{
			switch (temp.toInt())
			{
			case QSerialPort::Data5:
				serialPortManager_mEMSData->setDataBits(QSerialPort::Data5);
				break;
			case QSerialPort::Data6:
				serialPortManager_mEMSData->setDataBits(QSerialPort::Data6);
				break;
			case QSerialPort::Data7:
				serialPortManager_mEMSData->setDataBits(QSerialPort::Data7);
				break;
			case QSerialPort::Data8:
				serialPortManager_mEMSData->setDataBits(QSerialPort::Data8);
				break;
			default:
				break;
			}
		}
	}

	if (config->contains(serialPortManager_turnTable_stopBits))
	{
		QJsonValue temp = (*config)[serialPortManager_turnTable_stopBits];
		if (temp.isDouble())
		{
			switch (temp.toInt())
			{
			case QSerialPort::OneStop:
				serialPortManager_turnTable->setStopBits(QSerialPort::OneStop);
				break;
			case QSerialPort::OneAndHalfStop:
				serialPortManager_turnTable->setStopBits(QSerialPort::OneAndHalfStop);
				break;
			case QSerialPort::TwoStop:
				serialPortManager_turnTable->setStopBits(QSerialPort::TwoStop);
				break;
			default:
				break;
			}
		}
	}

	if (config->contains(serialPortManager_mEMSData_stopBits))
	{
		QJsonValue temp = (*config)[serialPortManager_mEMSData_stopBits];
		if (temp.isDouble())
		{
			switch (temp.toInt())
			{
			case QSerialPort::OneStop:
				serialPortManager_mEMSData->setStopBits(QSerialPort::OneStop);
				break;
			case QSerialPort::OneAndHalfStop:
				serialPortManager_mEMSData->setStopBits(QSerialPort::OneAndHalfStop);
				break;
			case QSerialPort::TwoStop:
				serialPortManager_mEMSData->setStopBits(QSerialPort::TwoStop);
				break;
			default:
				break;
			}
		}
	}

	if (config->contains(serialPortManager_turnTable_flowControl))
	{
		QJsonValue temp = (*config)[serialPortManager_turnTable_flowControl];
		if (temp.isDouble())
		{
			switch (temp.toInt())
			{
			case QSerialPort::NoFlowControl:
				serialPortManager_turnTable->setFlowControl(QSerialPort::NoFlowControl);
				break;
			case QSerialPort::HardwareControl:
				serialPortManager_turnTable->setFlowControl(QSerialPort::HardwareControl);
				break;
			case QSerialPort::SoftwareControl:
				serialPortManager_turnTable->setFlowControl(QSerialPort::SoftwareControl);
				break;
			default:
				break;
			}
		}
	}

	if (config->contains(serialPortManager_mEMSData_flowControl))
	{
		QJsonValue temp = (*config)[serialPortManager_mEMSData_flowControl];
		if (temp.isDouble())
		{
			switch (temp.toInt())
			{
			case QSerialPort::NoFlowControl:
				serialPortManager_mEMSData->setFlowControl(QSerialPort::NoFlowControl);
				break;
			case QSerialPort::HardwareControl:
				serialPortManager_mEMSData->setFlowControl(QSerialPort::HardwareControl);
				break;
			case QSerialPort::SoftwareControl:
				serialPortManager_mEMSData->setFlowControl(QSerialPort::SoftwareControl);
				break;
			default:
				break;
			}
		}
	}
}

//UI层
MemsAutoTestSoftware* ConfigSaveLoader::getMemsAutoTestSoftware()
{
	return memsAutoTestSoftware;
}
void ConfigSaveLoader::setMemsAutoTestSoftware(MemsAutoTestSoftware* memsAutoTestSoftware)
{
	this->memsAutoTestSoftware = memsAutoTestSoftware;
}
ParameterConsole* ConfigSaveLoader::getParameterConsole()
{
	return parameterConsole;
}
void ConfigSaveLoader::setParameterConsole(ParameterConsole* parameterConsole)
{
	this->parameterConsole = parameterConsole;
}
SetPositionModeDialog* ConfigSaveLoader::getSetPositionModeDialog()
{
	return setPositionModeDialog;
}
void ConfigSaveLoader::setSetPositionModeDialog(SetPositionModeDialog* setPositionModeDialog)
{
	this->setPositionModeDialog = setPositionModeDialog;
}
SetRateModeDialog* ConfigSaveLoader::getSetRateModeDialog()
{
	return setRateModeDialog;
}
void ConfigSaveLoader::setSetRateModeDialog(SetRateModeDialog* setRateModeDialog)
{
	this->setRateModeDialog = setRateModeDialog;
}
SetTurnTableAndThermostatDialog* ConfigSaveLoader::getSetTurnTableAndThermostatDialog()
{
	return setTurnTableAndThermostatDialog;
}
void ConfigSaveLoader::setSetTurnTableAndThermostatDialog(SetTurnTableAndThermostatDialog* setTurnTableAndThermostatDialog)
{
	this->setTurnTableAndThermostatDialog = setTurnTableAndThermostatDialog;
}

//功能层
MEMSDataCodec* ConfigSaveLoader::getMEMSDataCodec()
{
	return mEMSDataCodec;
}
void ConfigSaveLoader::setMEMSDataCodec(MEMSDataCodec* mEMSDataCodec)
{
	this->mEMSDataCodec = mEMSDataCodec;
}
MEMSDataHandler* ConfigSaveLoader::getMEMSDataHandler()
{
	return mEMSDataHandler;
}
void ConfigSaveLoader::setMEMSDataHandler(MEMSDataHandler* mEMSDataHandler)
{
	this->mEMSDataHandler = mEMSDataHandler;
}
MEMSDataSaver* ConfigSaveLoader::setMEMSDataSaver()
{
	return mEMSDataSaver;
}
void ConfigSaveLoader::setMEMSDataSaver(MEMSDataSaver* mEMSDataSaver)
{
	this->mEMSDataSaver = mEMSDataSaver;
}
ScriptRunner* ConfigSaveLoader::getScriptRunner()
{
	return scriptRunner;
}
void ConfigSaveLoader::setScriptRunner(ScriptRunner* scriptRunner)
{
	this->scriptRunner = scriptRunner;
}
TurnTableCodec* ConfigSaveLoader::getTurnTableCodec()
{
	return turnTableCodec;
}
void ConfigSaveLoader::setTurnTableCodec(TurnTableCodec* turnTableCodec)
{
	this->turnTableCodec = turnTableCodec;
}
LogSaver* ConfigSaveLoader::getLogSaver()
{
	return logSaver;
}
void ConfigSaveLoader::setLogSaver(LogSaver* logSaver)
{
	this->logSaver= logSaver;
}
//IO层
FileReader* ConfigSaveLoader::getFileReader()
{
	return fileReader;
}
void ConfigSaveLoader::setFileReader(FileReader* fileReader)
{
	this->fileReader = fileReader;
}
FileWriter* ConfigSaveLoader::getFileWriter()
{
	return fileWriter;
}
void ConfigSaveLoader::setFileWriter(FileWriter* fileWriter)
{
	this->fileWriter = fileWriter;
}
SerialPortManager* ConfigSaveLoader::getSerialPortManager_turnTable()
{
	return serialPortManager_turnTable;
}

void ConfigSaveLoader::setSerialPortManager_turnTable(SerialPortManager* serialPortManager_turnTable)
{
	this->serialPortManager_turnTable = serialPortManager_turnTable;
}
SerialPortManager* ConfigSaveLoader::getSerialPortManager_mEMSData()
{
	return serialPortManager_mEMSData;
}
void ConfigSaveLoader::setSerialPortManager_mEMSData(SerialPortManager* serialPortManager_mEMSData)
{
	this->serialPortManager_mEMSData = serialPortManager_mEMSData;
}